<?php
require('etc/config.php');
require('lib/php_sam.php');
date_default_timezone_set('PRC');
define('SAM_HOST', '6nww.com');
define('SAM_PORT', '1883');

//create a new connection object
$conn = new SAMConnection();

//start initialise the connection
$conn->connect(SAM_MQTT, array(SAM_HOST => MQTT_SERVER_HOST, SAM_PORT => MQTT_SERVER_POST));

// bik42a551db44e874ed/fb
//create a new MQTT message with the output of the shell command as the body
$msgCpu = new SAMMessage($_REQUEST['message']);

//send the message on the topic cpu
// $conn->send('topic://'.$_REQUEST['target'], $msgCpu);
$conn->send('topic://'.$_REQUEST['target'], $msgCpu);
// echo "<pre>";         
// print_r($_REQUEST);         
$conn->disconnect();
// echo "<pre>";         
// print_r(get_cfg_var('error_reporting'));
echo 'MQTT Message to ' . $_REQUEST['target'] . ' sent: ' . $_REQUEST['message']; 
?>